<template>
  <div>
    <!--修改表单 -->
    <el-dialog :title="'修改' + formSubmitDataCom.term_name" :visible.sync="DialogFormVisibleCom"
               :close-on-click-modal="false"
               :close-on-press-escape="false">
      <el-form ref="dataForm" :rules="rules" :model="formSubmitDataCom" label-position="right" label-width="160px"
               style="width: 90%; margin:10px auto;">

        <el-row :gutter="20">
          <el-col :span="9">
            <!-- 生成方案编号 -->
            <el-form-item :label="'a曲线-'+ parentData.a_cv_name" prop="a_term_weight">
              <el-input v-model="formSubmitDataCom.a_term_weight"
                        :disabled="formSubmitDataCom.a_term_weight == '0' ? true : false"/>
            </el-form-item>
          </el-col>
          <!-- 生成曲线类型 -->
          <el-col :span="6">
            <el-form-item label="运算符" prop="operator" label-width="80px">
              <el-select v-model="formSubmitDataCom.operator" class="filter-item" placeholder="Please select"
                         clearable>
                <el-option v-for="item in operator" :key="item.code" :label="item.name" :value="item.code"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="9">
            <!-- 生成方案名称 -->
            <el-form-item :label="'b曲线-'+ parentData.b_cv_name" prop="b_term_weight">
              <el-input v-model="formSubmitDataCom.b_term_weight"
                        :disabled="formSubmitDataCom.b_term_weight == '0' ? true : false"/>
            </el-form-item>
          </el-col>
        </el-row>


      </el-form>
      <div slot="footer" class="dialog-footer" style="text-align:center">
        <el-button @click="resetFormData">
          重置
        </el-button>
        <el-button type="primary" @click="updateData()">
          提交
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
// 这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
// import PageHeaderLayout from '@/layouts/PageHeaderLayout'
// import ApeDrawer from '@/components/ApeDrawer'
// import { mapGetters } from 'vuex'
// const calendarTypeOptions = [
//   { key: 'lp_code', display_name: 'lp_name' },
// ]

import {findoperator} from '../service/baseApi'
import resetFormSubmitData from '@/views/mixins/resetFormSubmitData'

export default {
  name: 'submitForm',
  mixins: [resetFormSubmitData],
  components: {
    //PageHeaderLayout,
  },
  props: {
    dialogFormVisible: {
      type: Boolean,
      default: false
    },

    formSubmitData: {
      type: Object,
      default: function () {
        return {
          id: undefined,
          a_term_weight: '',
          b_term_weight: '',
          term_name: '',
          remark: ''
        }
      }
    },
    parentData: {
      type: Object,
      default: function () {
        return {
          id: undefined,
          a_cv_name: '',
          b_cv_name: ''
        }
      }
    },
  },

  // 定义属性
  data() {
    return {
      rules: {
        a_term_weight: [{required: true, message: 'a曲线-' + this.parentData.a_cv_name + '必填', trigger: 'change'}],
        b_term_weight: [{required: true, message: 'b曲线-' + this.parentData.b_cv_name + '必填', trigger: 'change'}],
        operator: [{required: true, message: '运算符必填', trigger: 'change'}],

      },
      operator: []
    }
  },
  // 计算属性，会监听依赖属性值随之变化
  computed: {
    DialogFormVisibleCom: {
      get() {
        return this.dialogFormVisible
      },
      set(val) {
        this.$emit('update:dialogFormVisible', val)
      }
    },
    formSubmitDataCom: {
      get() {
        return this.formSubmitData
      },
      set(val) {
        this.$emit('update:formSubmitData', val)
      }
    }
  },
  // 监控data中的数据变化
  watch: {},
  // 方法集合
  methods: {
    // 获取移动平均曲线下拉数据
    getlist() {
      // 获取运算符下拉框下拉
      findoperator().then(({data}) => {
        console.log(data)
        this.operator = data.rows
      })
    },
    // 重置
    resetFormData() {
      let exclude = []
      if (this.formSubmitDataCom.a_term_weight == 0) {
        exclude = [
          'id',
          'a_term_weight'
        ]
      }
      if (this.formSubmitDataCom.b_term_weight == 0) {
        exclude = [
          'id',
          'b_term_weight'
        ]
      }
      this.$emit('resetFormDataEmit', {exclude})
    },
    //修改
    updateData() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.$emit('handleFromUpdateDataEmit')
        }
      })
    },

  },
  // 生命周期 - 创建完成（可以访问当前this实例）
  created() {
    this.getlist()
  },
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {
  },
  beforeCreate() {
  }, // 生命周期 - 创建之前
  beforeMount() {
  }, // 生命周期 - 挂载之前
  beforeUpdate() {
  }, // 生命周期 - 更新之前
  updated() {
  }, // 生命周期 - 更新之后
  beforeDestroy() {
  }, // 生命周期 - 销毁之前
  destroyed() {
  }, // 生命周期 - 销毁完成
  activated() {
  }, // 如果页面有keep-alive缓存功能，这个函数会触发
}
</script>

<style lang='scss' scoped>

</style>
